<?php

namespace App\Http\Controllers;

use App\Models\WxUser;
use App\Tools\JsonTools;
use Illuminate\Http\Request;

class ChatController extends Controller
{
        /**
         * @Notes:
         * @Author: 遇见
         * @Date: 2022/11/15
         * @Time: 10:20
         * 获取当前用户登录的id
         */
        public function getUid(){
            $uid = \request()->id;
            if(empty($uid)){
                return JsonTools::JsonError();
            }else{
                return JsonTools::JsonSuccess($uid);
            }
        }
        /**
         * @Notes:
         * @Author: 遇见
         * @Date: 2022/11/14
         * @Time: 20:04
         * 获取用户昵称
         */
        public function getUserName(){
            $uid = \request()->id;
            $user_name = WxUser::where('id',$uid)->first(['user_name']);
            if(empty($user_name)){
                return JsonTools::JsonError();
            }else{
                return JsonTools::JsonSuccess($user_name);
            }
        }

        /**
         * @Notes:
         * @Author: 遇见
         * @Date: 2022/11/15
         * @Time: 9:58
         * @return array
         * @throws \Psr\Container\ContainerExceptionInterface
         * @throws \Psr\Container\NotFoundExceptionInterface
         * 获取接收消息用户昵称
         */
        public function getLeftName(){
            $uid = \request()->get('uid');
            $user_name = WxUser::where('id',$uid)->first(['user_name']);
            if(empty($user_name)){
                return JsonTools::JsonError();
            }else{
                return JsonTools::JsonSuccess($user_name);
            }
        }

        /**
         * @Notes:
         * @Author: 遇见
         * @Date: 2022/11/15
         * @Time: 9:59
         * @return array
         * @throws \Psr\Container\ContainerExceptionInterface
         * @throws \Psr\Container\NotFoundExceptionInterface
         * 获取接收消息的头像
         */
        public function getLeftImage(){
            $uid = \request()->get('uid');
            $user_image = WxUser::where('id',$uid)->first(['user_image']);
            if(empty($user_image)){
                return JsonTools::JsonError();
            }else{
                return JsonTools::JsonSuccess($user_image);
            }
        }

        /**
         * @Notes:
         * @Author: 遇见
         * @Date: 2022/11/14
         * @Time: 20:04
         * 获取用户头像
         */
        public function getUserImage(){
            $uid = \request()->id;
            $user_image = WxUser::where('id',$uid)->first(['user_image']);
            if(empty($user_image)){
                return JsonTools::JsonError();
            }else{
                return JsonTools::JsonSuccess($user_image);
            }
        }
}
